package com.hzdl.library.dao.impl;

import com.hzdl.library.dao.AdminDao;
import com.hzdl.library.domain.Admin;
import com.hzdl.library.util.JDBCUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class AdminDaoImpl implements AdminDao {
    JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    @Override
    public Admin selectAdmin(Integer id, String passwd) {
        String sql = "select * from admin where admin_id = ? and password = ?";
        try {
            return template.queryForObject(sql, new BeanPropertyRowMapper<Admin>(Admin.class), id, passwd);
        } catch (DataAccessException e) {
//            e.printStackTrace();
            return null;
        }

    }

    @Override
    public int updateAdmin(Integer id, String newPass) {
        String sql = "update admin set password = ? where admin_id = ?";
        return template.update(sql,newPass,id);
    }
}
